import pandas as pd
import os

# 定义文件夹路径
folder_path = 'data'

# 初始化两个空的DataFrame来存储高温和低温数据
high_temp_df = pd.DataFrame(columns=['datetime', 'temperature'])
low_temp_df = pd.DataFrame(columns=['datetime', 'temperature'])

# 遍历文件夹中的所有Excel文件
for filename in os.listdir(folder_path):
    if filename.endswith('.xlsx'):
        file_path = os.path.join(folder_path, filename)
        # 读取Excel文件
        df = pd.read_excel(file_path)
        
        # 筛选高温和低温数据
        high_temp = df[(df['温度'] > 68)]
        low_temp = df[(df['温度'] < 32)]
        
        # 添加到对应的DataFrame中
        high_temp_df = pd.concat([high_temp_df, high_temp], ignore_index=True)
        low_temp_df = pd.concat([low_temp_df, low_temp], ignore_index=True)

# 将高温数据保存到高温.xlsx文件中
high_temp_output_path = '高温.xlsx'
high_temp_df.to_excel(high_temp_output_path, index=False)

# 将低温数据保存到低温.xlsx文件中
low_temp_output_path = '低温.xlsx'
low_temp_df.to_excel(low_temp_output_path, index=False)

print(f"高温数据已保存到 {high_temp_output_path}")
print(f"低温数据已保存到 {low_temp_output_path}")

import pandas as pd
import os

# 定义文件夹路径
folder_path = 'data'

# 初始化两个空的DataFrame来存储高温和低温数据
high_temp_df = pd.DataFrame(columns=['时间', '温度'])
low_temp_df = pd.DataFrame(columns=['时间', '温度'])

# 遍历文件夹中的所有Excel文件
for filename in os.listdir(folder_path):
    if filename.endswith('.xlsx'):
        file_path = os.path.join(folder_path, filename)
        # 读取Excel文件
        df = pd.read_excel(file_path)
        
        # 筛选高温和低温数据
        high_temp = df[(df['温度'] > 68)]
        low_temp = df[(df['温度'] < 32)]
        
        # 添加到对应的DataFrame中
        high_temp_df = pd.concat([high_temp_df, high_temp], ignore_index=True)
        low_temp_df = pd.concat([low_temp_df, low_temp], ignore_index=True)

# 将高温数据保存到高温.xlsx文件中
high_temp_output_path = '高温.xlsx'
high_temp_df.to_excel(high_temp_output_path, index=False)

# 将低温数据保存到低温.xlsx文件中
low_temp_output_path = '低温.xlsx'
low_temp_df.to_excel(low_temp_output_path, index=False)

print(f"高温数据已保存到 {high_temp_output_path}")
print(f"低温数据已保存到 {low_temp_output_path}")